<template>
    <view class="box">
        <view class="main">
			<block v-if="is_hs==5">
				<!--订单列表-->
				<indexmainlis ref="indexmain" @showtabbar="showtabbarchange" v-if="show === 0"></indexmainlis>
				<!--我的页面-->
				<myhome v-if="show === 1" :info="info" @index="gettabindx"></myhome>
			</block>
			<block v-else>
				<!--订单列表-->
				<indexmainlis ref="indexmain" @showtabbar="showtabbarchange" v-if="show === 0"></indexmainlis>
				<view v-if="show === 1">
				    <myorder></myorder>
				</view>
				
				<!--我的页面-->
				<myhome v-if="show === 2" :info="info" @index="gettabindx"></myhome>
			</block>

        </view>
        <!-- 自定义tabbar -->
        <view>
            <tabbar v-show="showtabbar" ref="tabbar" @clicktabindex="gettabindx" :tabbars="tabbarsarr"></tabbar>
        </view>
    </view>
</template>

<script>
    import indexmainlis from './indexmainlist.vue'
    import myhome from './myhome/myhome'
    import myorder from '../../../mypages/My_order/myorders.vue'
    import tabbar from '../../../custom_tab_bar/cu_tab_bar.vue'

    export default {
        components: {
            myhome,
            indexmainlis,
            tabbar,
            myorder
        },
        data() {
            return {
                // main 展示得内容
                show: 0,
                // tabbar显示与隐藏
                showtabbar: true,
				is_hs:0,
                tabbarsarr: [
                    {
                        name: '收货接单',
                        img: '../static/img/navimg/Tab-icon-02@3x.png',
                        activeimg: '../static/img/navimg/Tab-icon-Active-02@3x.png'
                    },
                    {
                        name: '卖货订单',
                        img: '../static/img/navimg/Tab-icon-02@3x.png',
                        activeimg: '../static/img/navimg/Tab-icon-Active-02@3x.png'
                    },
                    {
                        name: '我的',
                        img: '../static/img/navimg/Tab-icon-04@3x.png',
                        activeimg: '../static/img/navimg/Tab-icon-Active-04@3x.png'
                    }
                ],
                info: {}
            }
        },
        mounted() {
            this._getwptypelist();
        },
        onShow() {
            if(this.$store.state.isEditOrder == 1) {
                this.$refs.indexmain._getRecoverList();
                this.$store.commit('setEditOrder', 0);
            }
            this._getInfo();
        },
        methods: {
            _getInfo() {
                this.$u.api.getInfo().then(res => {
                    this.info = res;
                    uni.setStorageSync('is_hs', res.is_hs);
                    this.$store.commit('setUserInfo', res)
                    uni.setStorageSync('userInfo', res);
                    this.$store.commit('setIsUserEdit', 0);
                    if(res.is_hs == 0 || res.is_hs == 2) {
                        uni.reLaunch({
                            url: '/mypages/User/index'
                        });
                        this.$store.commit('changeactive', 0)
                    }
					this.is_hs = res.is_hs
					if(res.is_hs == 5){
						this.tabbarsarr=  [
						    {
						        name: '收货接单',
						        img: '../static/img/navimg/Tab-icon-02@3x.png',
						        activeimg: '../static/img/navimg/Tab-icon-Active-02@3x.png'
						    },
						    {
						        name: '我的',
						        img: '../static/img/navimg/Tab-icon-04@3x.png',
						        activeimg: '../static/img/navimg/Tab-icon-Active-04@3x.png'
						    }
						]
					} else{
						this.tabbarsarr= [
						    {
						        name: '收货接单',
						        img: '../static/img/navimg/Tab-icon-02@3x.png',
						        activeimg: '../static/img/navimg/Tab-icon-Active-02@3x.png'
						    },
						    {
						        name: '卖货订单',
						        img: '../static/img/navimg/Tab-icon-02@3x.png',
						        activeimg: '../static/img/navimg/Tab-icon-Active-02@3x.png'
						    },
						    {
						        name: '我的',
						        img: '../static/img/navimg/Tab-icon-04@3x.png',
						        activeimg: '../static/img/navimg/Tab-icon-Active-04@3x.png'
						    }
						]
					}
                }).catch(e => {
                })
            },
            // 跳转 tabbar，改变 main 展示内容
            gettabindx(index) {
                this.show = this.$store.state.active
            },
            // 切换 tabbar 显示与隐藏
            showtabbarchange() {
                this.showtabbar = !this.showtabbar
            },
            _getwptypelist() {
                 if(uni.getStorageSync('isMessage') != 1) {
                    uni.showModal({
                        title: '提示',
                        content: '是否授权订阅消息',
                        success: function (res) {
                            if (res.confirm) {
                                // uni.setStorageSync('isMessage', 1);
                                uni.requestSubscribeMessage({
                                    tmplIds: [
                                        getApp().globalData.capitalKey,
                                        getApp().globalData.dispatchKey,
                                        getApp().globalData.orderTakingKey,
                                    ],
                                })
                            } else if (res.cancel) {
                                // console.log('用户点击取消');
                            }
                        }
                    });
                 }
                this.$u.api.getwptypelist().then(res => {
                    this.wptypelist = res;
                    res.forEach((item,index) => {
                        item.plist.forEach((it,idx) => {
                            return it.extra = it.u_price+','+it.unit
                        })
                    })
                    this.$store.commit('setWptypeList', res)
                })
            },
        },
        onPullDownRefresh() {
            uni.stopPullDownRefresh()
        }
    }
</script>

<style lang="scss" scoped>
    .box {
        min-height: 100vh;
        background-color: #EEEEEE;
    }

    .main {
        // padding-bottom: 25%;
    }
</style>
